/**
 * 
 */
package com.example.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.demo.services.WeChatSubscribeMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author bueryouth
 */
@ResponseBody
@RestController
public class GetData {
    @PostMapping(value = "/getWechat", produces = "application/json;charset=UTF-8")
    public Map<String, String> Test(@RequestBody Map<String, String> commandInfo) {

        System.out.println(commandInfo.toString());
        Map<String, String> res = new HashMap<String, String>();
        res.put("01", "xm");
        res.put("02", "lh");
        res.put("03", "dd");
        res.put("04", "cs");
        return res;
    }

    @RequestMapping(value = "/json/data", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public Map<String, String> getByJSON(@RequestBody JSONObject jsonParam) {
        // 直接将json信息打印出来
        System.out.println(jsonParam.toJSONString());

        // 将获取的json数据封装一层，然后在给返回
        JSONObject result = new JSONObject();
        result.put("msg", "ok");
        result.put("method", "json");
        result.put("data", jsonParam);
        Map<String, String> res = new HashMap<String, String>();
        res.put("01", "xm");
        res.put("02", "lh");
        res.put("03", "dd");
        res.put("04", "cs");
        return res;
        // return result.toJSONString();
    }

    @GetMapping("/setWechat")
    public Map<String, String> go() {
        // TODO 自动生成的方法存根
        Map<String, String> res = new HashMap<String, String>();
        res.put("1", "qweq");
        res.put("211", "121");
        res.put("11", "qweq");
        res.put("21", "121");
        return res;
    }

    @Autowired
    private WeChatSubscribeMessage weChatSubscribeMessage;

    // @GetMapping("/test")
    // public void test() {
    // String str =
    // "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET";
    // weChatSubscribeMessage.getAccessToken();
    // GetTime getTime = new GetTime();
    // System.out.println(getTime.getTime());
    // }
}
